package org.doxla.oomwatch.observerable;

import java.util.List;

/**
 * An {@link AbstractOomWatcher} that has thresholdExeeded true when the
 * maximum memory available - the current memory useage for the Virtual 
 * Machine is less than the threshold value.
 * 
 * @author danoxlade
 *
 */
public class AvailableMemoryThresholdOomWatcher extends AbstractOomWatcher {

	public AvailableMemoryThresholdOomWatcher(){
		super();
	}
	
	public AvailableMemoryThresholdOomWatcher(List<OomObserver> obs, long threshold) {
		super(obs,threshold);
	}
	
	@Override
	public boolean thresholdExceeded() {

		long availableMem = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory();
		return availableMem < getThreshold();
	}

}
